package com.xbongbong.saas.enums;

import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;

import static com.xbongbong.saas.enums.SubOptionTableHeadEnum.*;
import static com.xbongbong.saas.enums.SubOptionTableHeadEnum.PRODUCT_COST_TOTAL;
import static com.xbongbong.saas.enums.SubOptionTableHeadEnum.PRODUCT_WAREHOUSE;

/**
 * 列表页options（下拉）的表头枚举
 *
 * @author chaoxiong.lei
 * @Date 21:08 2019/3/11
 * @since v1.0
 * @return
 **/
@Getter
public enum OptionTableHeadEnum {
    // 列表页options（下拉）的表头枚举
    PRODUCT(XbbRefTypeEnum.PRODUCT.getCode(), Arrays.asList(PRODUCT_SPEC_NO, PRODUCT_BARCODE, PRODUCT_SPECIFICATION,PRODUCT_IMAGE, PRODUCT_COST, PRODUCT_STOCK, PRODUCT_PRICE)),
    STOCK_SEARCH(XbbRefTypeEnum.STOCK_SEARCH.getCode(), Arrays.asList(PRODUCT_WAREHOUSE, PRODUCT_STOCK, PRODUCT_COST, PRODUCT_COST_TOTAL)),
    WARNING_SEARCH(XbbRefTypeEnum.WARNING_SEARCH.getCode(), Arrays.asList(WARNING_WAREHOUSE, WARNING_TYPE, PRODUCT_STOCK, WARNING_UPPER_LIMIT, WARNING_LOWER_LIMIT)),
    GUARANTEE_SEARCH(XbbRefTypeEnum.GUARANTEE_SEARCH.getCode(), Arrays.asList(WARNING_WAREHOUSE, GUARANTEE_STATUS, GUARANTEE_BATCH, GUARANTEE_PRODUCE_DATE, GUARANTEE_PERIOD, PRODUCT_NUM)),

    UNKNOW(XbbRefTypeEnum.UNKNOWN.getCode(), null),
    ;
    private Integer businessType;
    private List<SubOptionTableHeadEnum> list;

    OptionTableHeadEnum(Integer businessType, List<SubOptionTableHeadEnum> list) {
        this.businessType = businessType;
        this.list = list;
    }

    /**
     * 根据businessType获取对应枚举
     *
     * @param businessType 业务类型
     * @author chaoxiong.lei
     * @Date 21:56 2019/3/11
     * @since v1.0
     * @return com.xbongbong.saas.enums.OptionTableHeadEnum
     **/
    public static OptionTableHeadEnum getByBusinessType(Integer businessType) {
        for (OptionTableHeadEnum cacheCode : values()) {
            if (businessType.equals(cacheCode.getBusinessType())) {
                return cacheCode;
            }
        }
        return null;
    }

    /**
     * 根据businessType获取对应表头列表
     *
     * @param businessType 业务类型
     * @author chaoxiong.lei
     * @Date 21:56 2019/3/11
     * @since v1.0
     * @return com.xbongbong.saas.enums.OptionTableHeadEnum
     **/
    public static List<SubOptionTableHeadEnum> getListByBusinessType(Integer businessType) {
        for (OptionTableHeadEnum cacheCode : values()) {
            if (Objects.equals(businessType, cacheCode.getBusinessType())) {
                return cacheCode.getList();
            }
        }
        return null;
    }
}
